define(['egis'], function (egis) {
    Window.deserializer = Window.deserializer || new egis.core.Deserializer();
    Window.container = Window.container || {};
    var toolTips = toolTips || [];
    dsBridge.register('create_TooltipWare', function (sourceId, mapId) {
        var map = Window.container[mapId];
        var tooltipWare = new egis.widget.TooltipWare({
            map: map
        });
        Window.container[sourceId] = tooltipWare;
    })

    dsBridge.register('TooltipWare_add', function (sourceId, tooltipId, clearLast) {
        try{
            var source = Window.container[sourceId];
            var tooltip = Window.container[tooltipId];
            source.add(tooltip, clearLast);
            toolTips.push(tooltip);
        }
        catch (e){
            alert(e)
        }
    })

    dsBridge.register('TooltipWare_remove', function (sourceId, tooltipId) {
        var source = Window.container[sourceId];
        var tooltip = Window.container[tooltipId];
        source.remove(tooltipId);
        var index = toolTips.index(tooltip);
        if(index >= 0){
            toolTips.splice(index, 1);
        }
        delete Window.container[tooltipId];
        tooltip = null;
    })

    dsBridge.register('TooltipWare_clear', function (sourceId) {
        var source = Window.container[sourceId];
        source.clear();
        toolTips.forEach(function (toolTip) {
            delete Window.container[toolTip.id];
            tooltip = null;
        })
    })
})